package com.rookie.jeesdp.service.impl;

import com.rookie.jeesdp.entity.admin.LoginUser;
import com.rookie.jeesdp.service.LoginUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Set;

@Service
public class LoginUserServiceImpl implements LoginUserService {

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        LoginUser loginUser = new LoginUser();
        loginUser.setUsername("admin");
        loginUser.setPassword(passwordEncoder.encode("admin"));
        Set<String> set = new HashSet<>();
        set.add("demo");
        loginUser.setPermissions(set);
        return loginUser;
    }
}
